const HotModel = require("../../models/HotsModel");

const HotService = {
  addHot: async ({ title, content, category, cover, isPublish, editTime }) => {
    return HotModel.create({
      title,
      content,
      category,
      isPublish,
      cover,
      editTime,
    });
  },
  updateHot: async ({
    _id,
    title,
    content,
    category,
    cover,
    isPublish,
    editTime,
  }) => {
    if (cover) {
      return HotModel.updateOne(
        { _id },
        {
          title,
          content,
          category,
          isPublish,
          cover,
          editTime,
        }
      );
    } else {
      return HotModel.updateOne(
        { _id },
        {
          title,
          content,
          category,
          isPublish,
          editTime,
        }
      );
    }
  },
  getHotsList: async ({ _id }) => {
    return _id ? HotModel.find({ _id }) : HotModel.find();
  },
  publish: async ({ _id, isPublish, editTime }) => {
    return HotModel.updateOne(
      { _id },
      {
        isPublish,
        editTime,
      }
    );
  },
  deleteHot: async ({ _id }) => {
    return HotModel.deleteOne({ _id });
  },
};

module.exports = HotService;
